<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>管理后台</title>
    <link rel="stylesheet/less" href="../../../static/css/index.less"/>
    <link rel="stylesheet" href="../../../static/layui/css/layui.css"/>
    <link rel="stylesheet" href="../../../static/css/jquery.pagination.css"/>
    <script src="../../../static/js/jquery-1.12.3.js"></script>
    <script src="../../../static/js/less.min.js"></script>
    <script src="../../../static/layui/layui.js"></script>
    <script src="../../../static/js/ajaxfileupload.js"></script>
    <script src="../../../static/layer/layer.js"></script>
    <SCRIPT language=javascript src="../../static/layer/layer.js"></SCRIPT>
</head>
<style>

</style>
<body class="layui-layout-body">

{% include "/admin/top.html" %}
{% include "/admin/left.html" %}
<div id="box" class="fl">
    <div class="content" style="height: 100%">
        <h3 style="color:  #3D89CB">门店列表</h3>
        <div class="search">
            <form action="/admin/store/list.html" method="get">
                <label>昵称：</label><input class="name" value="{% if request.args.get('storeName') != None %}{{ request.args.get('storeName') }}{% endif %}"
                                         name="storeName" type="text" placeholder="请输入用户名"/>

                <button class="s_button">搜索</button>
            </form>
        </div>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <thead>
            <tr>
                <th width="10%">门店ID</th>
                <th width="12%">门店照片</th>
                <th width="10%">门店昵称</th>
                <th width="20%">创建时间</th>
                <th width="10%">状态</th>
                <th width="20%">操作</th>
            </tr>
            </thead>

            <tbody>
            <tr>
                {% if res['code']==400 %}
                    <tr class="color2">
                        <td colspan=8 align="center">暂无数据</td>
                    </tr>
                {% elif res['code']==200 %}
                    {% for data in res['data'] %}

                        <tr>
                            <td>{{ data.storeId }}</td>
                            <td><img src="{{ data.storeUrl }}" style="width: 50px;height: 50px; padding: 3px "></td>
                            <td><a href="/admin/machine/list.html?storeId={{ data.storeId }}"><span style="color: red">{{ data.storeName }}</span></a></td>
                            <td>{{ data.addTime }}</td>
                            <td>
                                {% if data.status==0 %}
                                    筹建中
                                {% elif data.status==1 %}
                                    使用中
                                {% elif data.status==2 %}
                                    维护中
                                {% endif %}
                            </td>
                            <td>
                                <button><span style="color: green"><a
                                        href="/admin/store/edit.html?storeId={{ data.storeId }}">编辑</a></span>
                                </button>
                                {% if data.status == 0 %}
                                    <button class="ccc">
                                        <a href="#" onclick="start({{ data.storeId }})">启用</a>
                                    </button>
                                {% elif data.status == 1 %}
                                    <button class="green">
                                        <a href="#" onclick="stop({{ data.storeId }})">禁用</a>
                                    </button>
                                {% elif data.status == 2 %}
                                    <button class="green">
                                        <a href="#" onclick="start({{ data.storeId }})">启用</a>
                                    </button>
                                {% endif %}
                                <button class="red">
                                    <a href="#" onclick="delete_store({{ data.storeId }})">删除</a>
                                </button>
                            </td>

                        </tr>
                    {% endfor %}
                {% endif %}

            </tbody>
        </table>

        {% if res.max_page > 0 %}
            <div class="ui-pagination-container">
                {% if res.page > 1 %}
                    <a href="/admin/store/list.html?page=1" class="ui-pagination-page-item"
                       data-current="1">首页</a>
                    <a href="/admin/store/list.html?page={{ res.page - 1 }}" class="ui-pagination-page-item"
                       data-current="1">上一页</a>
                {% endif %}
                {% if res.page - 2 > 0 %}
                    <a href="/admin/store/list.html?page={{ res.page - 2 }}" class="ui-pagination-page-item"
                       data-current="1">{{ res.page - 2 }}</a>
                {% endif %}
                {% if res.page - 1 > 0 %}
                    <a href="/admin/store/list.html?page={{ res.page - 1 }}" class="ui-pagination-page-item"
                       data-current="1">{{ res.page - 1 }}</a>
                {% endif %}
                <a href="javascript:void(0);" class="ui-pagination-page-item active"
                   data-current="2">{{ res.page }}</a>
                {% if res.page + 1 <= res.max_page %}
                    <a href="/admin/store/list.html?page={{ res.page + 1 }}" class="ui-pagination-page-item"
                       data-current="3">{{ res.page + 1 }}</a>
                {% endif %}
                {% if res.page + 2 <= res.max_page %}
                    <a href="/admin/store/list.html?page={{ res.page + 2 }}" class="ui-pagination-page-item"
                       data-current="3">{{ res.page + 2 }}</a>
                {% endif %}
                {% if res.page + 1 <= res.max_page %}
                    <a href="/admin/store/list.html?page={{ res.page + 1 }}" class="ui-pagination-page-item"
                       data-current="3">下一页</a>
                    <a href="/admin/store/list.html?page={{ res.max_page }}" class="ui-pagination-page-item"
                       data-current="12">尾页</a>
                {% endif %}
            </div>
        {% endif %}
    </div>
</div>
</div>

</body>
</html>

<script>
    function stop(id) {
        layer.open({
            content: '你确定禁用',
            btn: ['确认', '取消'],
            shadeClose: false,
            yes: function () {
                $.ajax({
                    url: '/admin/store/stop',
                    type: 'post',
                    data: {
                        'storeId': id
                    },
                    dataType: 'json',
                    success: function (msg) {
                        if (msg.status == 1) {
                            layer.msg("操作成功！", {time: 2000}, function () {
                                window.location.href = location.pathname;
                            });


                        } else {
                            layer.msg("操作失败！");
                        }
                    }
                });
            }
        });
    }
    function start(id) {
        layer.open({
            content: '你确定激活',
            btn: ['确认', '取消'],
            shadeClose: false,
            yes: function () {
                $.ajax({
                    url: '/admin/store/start',
                    type: 'post',
                    data: {
                        'storeId': id
                    },
                    dataType: 'json',
                    success: function (msg) {
                        if (msg.status == 1) {
                            layer.msg("操作成功！", {time: 2000}, function () {
                                window.location.href = location.pathname;
                            });


                        } else {
                            layer.msg("操作失败！");
                        }
                    }
                });
            }
        });
    }

    function delete_store(id) {
        layer.open({
            content: '你确定删除相应的门店下面的机器',
            btn: ['确认', '取消'],
            shadeClose: false,
            yes: function () {
                $.ajax({
                    url: '/admin/store/delete',
                    type: 'post',
                    data: {
                        'storeId': id
                    },
                    dataType: 'json',
                    success: function (msg) {
                        if (msg.status == 1) {
                            layer.msg("操作成功！", {time: 2000}, function () {
                                window.location.href = location.pathname;
                            });


                        } else {
                            layer.msg("操作失败！");
                        }
                    }
                });
            }
        });
    }

</script>


